{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style=\"color:#777777;background-color:#ffffff;font-size:12px;text-align:right;\">\n",
    "\tprepared by Abuzer Yakaryilmaz (QuSoft@Riga) | November 08, 2018\n",
    "</div>\n",
    "<table><tr><td><i> I have some macros here. If there is a problem with displaying mathematical formulas, please run me to load these macros.</i></td></td></table>\n",
    "$ \\newcommand{\\bra}[1]{\\langle #1|} $\n",
    "$ \\newcommand{\\ket}[1]{|#1\\rangle} $\n",
    "$ \\newcommand{\\braket}[2]{\\langle #1|#2\\rangle} $\n",
    "$ \\newcommand{\\inner}[2]{\\langle #1,#2\\rangle} $\n",
    "$ \\newcommand{\\biginner}[2]{\\left\\langle #1,#2\\right\\rangle} $\n",
    "$ \\newcommand{\\mymatrix}[2]{\\left( \\begin{array}{#1} #2\\end{array} \\right)} $\n",
    "$ \\newcommand{\\myvector}[1]{\\mymatrix{c}{#1}} $\n",
    "$ \\newcommand{\\myrvector}[1]{\\mymatrix{r}{#1}} $\n",
    "$ \\newcommand{\\mypar}[1]{\\left( #1 \\right)} $\n",
    "$ \\newcommand{\\mybigpar}[1]{ \\Big( #1 \\Big)} $\n",
    "$ \\newcommand{\\sqrttwo}{\\frac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\dsqrttwo}{\\dfrac{1}{\\sqrt{2}}} $\n",
    "$ \\newcommand{\\onehalf}{\\frac{1}{2}} $\n",
    "$ \\newcommand{\\donehalf}{\\dfrac{1}{2}} $\n",
    "$ \\newcommand{\\hadamard}{ \\mymatrix{rr}{ \\sqrttwo & \\sqrttwo \\\\ \\sqrttwo & -\\sqrttwo }} $\n",
    "$ \\newcommand{\\vzero}{\\myvector{1\\\\0}} $\n",
    "$ \\newcommand{\\vone}{\\myvector{0\\\\1}} $\n",
    "$ \\newcommand{\\vhadamardzero}{\\myvector{ \\sqrttwo \\\\  \\sqrttwo } } $\n",
    "$ \\newcommand{\\vhadamardone}{ \\myrvector{ \\sqrttwo \\\\ -\\sqrttwo } } $\n",
    "$ \\newcommand{\\myarray}[2]{ \\begin{array}{#1}#2\\end{array}} $\n",
    "$ \\newcommand{\\X}{ \\mymatrix{cc}{0 & 1 \\\\ 1 & 0}  } $\n",
    "$ \\newcommand{\\Z}{ \\mymatrix{rr}{1 & 0 \\\\ 0 & -1}  } $\n",
    "$ \\newcommand{\\Htwo}{ \\mymatrix{rrrr}{ \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} & \\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} \\\\ \\frac{1}{2} & -\\frac{1}{2} & -\\frac{1}{2} & \\frac{1}{2} } } $\n",
    "$ \\newcommand{\\CNOT}{ \\mymatrix{cccc}{1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 0 & 1 \\\\ 0 & 0 & 1 & 0} } $\n",
    "$ \\newcommand{\\norm}[1]{ \\left\\lVert #1 \\right\\rVert } $"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h2>Reflections</h2>\n",
    "\n",
    "We have a single qubit, and all (real-valued) quantum states form the unit circle.\n",
    "\n",
    "Reflection is the second type of quantum operator on the unit circle.\n",
    "\n",
    "Reflections over the x-axis and y-axis are the basic examples."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Reflection over the x-axis and y-axis </h3>\n",
    "\n",
    "Let $ \\ket{u} = \\myvector{\\frac{3}{5} \\\\ \\frac{4}{5} } $ be a quantum state.\n",
    "\n",
    "<img src=\"../images/reflections_x_y.jpg\" width=\"40%\"> \n",
    "\n",
    "Its reflection over x-axis will be $ \\ket{u_x} = \\myrvector{\\frac{3}{5} \\\\ - \\frac{4}{5} } $.\n",
    "\n",
    "Its reflection over y-axis will be $ \\ket{u_y} = \\myrvector{-\\frac{3}{5} \\\\ \\frac{4}{5} } $.\n",
    "\n",
    "Both cases can be easily seen from the figure above."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we apply the same reflections once more, we get the original quantum state.\n",
    "\n",
    "The reflection on $x$-axis: The second entry of the vector is multiplied by $ (-1) $.\n",
    "\n",
    "Its matrix form is $ \\Z $.\n",
    "\n",
    "The reflection on $y$-axis: The first entry of the vector is multiplied by $ (-1) $.\n",
    "\n",
    "Its matrix form is $ \\mymatrix{rr}{ -1 & 0 \\\\ 0 & 1 } $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Reflection over an arbitrary axis </h3>\n",
    "\n",
    "The reflection axis can be arbitrary as shown below.\n",
    "\n",
    "<img src=\"../images/reflected_vector.jpg\" width=\"40%\"> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "What we need to know is the angle between the original vector and the reflection axis.\n",
    "\n",
    "If this angle is $ \\theta $, then the original vector is rotated with angle $ -2\\theta $ to obtain the reflected vector over the specified axis.\n",
    "\n",
    "The reflected vector is reflected again to the original vector by rotation with angle $ 2 \\theta $."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> The angle between two quantum states </h3>\n",
    "\n",
    "We use python to find this angle. \n",
    "\n",
    "<u>Technical note:</u>\n",
    "\n",
    "There is a formula to find the angle between two vectors $u$ and $v$: \n",
    "\n",
    "$ \\cos \\alpha = \\dfrac{(u,v)}{|u| \\cdot |v|} $, where $ (u,v) $ is the inner product of the vectors and $ |\\cdot| $ is the length of a given vector.\n",
    "\n",
    "If the vectors are quantum states, then their lengths are already 1. \n",
    "\n",
    "Thus the formula is $ \\cos \\alpha = \\braket{u}{v} \\Rightarrow \\alpha = \\arccos( \\braket{u}{v} ) $, where $ \\arccos $ is the inverse cosine function. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4>Define function <font color=\"blue\">angle_between_two_quantum_states</font></h4>\n",
    "\n",
    "This function return the angle (between $ 0 $ and $ \\pi $) between two quantum states.\n",
    "\n",
    "The inputs must be two quantum states, i.e., the vectors of length 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import acos # acos is the inverse of function cosine\n",
    "from math import pi \n",
    "\n",
    "def angle_between_two_quantum_states(quantum_state1,quantum_state2):\n",
    "    inner_product = quantum_state1[0] * quantum_state2[0] + quantum_state1[1] * quantum_state2[1]\n",
    "    return acos(inner_product) \n",
    "\n",
    "print(\"function 'angle_between_two_quantum_states' is defined now, and so it can be used in the following part\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4>Test function <font color=\"blue\">angle_between_two_quantum_states</font> </h4>\n",
    "\n",
    "We test the function in a few cases."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"the angle between |0> and |1> is pi/2 (90 degree)\")\n",
    "print(angle_between_two_quantum_states([1,0],[0,1]),\"is the angle between |0> and |1>\")\n",
    "print(pi/2,\"is the value of pi/2\")\n",
    "print()\n",
    "\n",
    "print(\"the angle between |0> and the quantum state [3/5,4/5] is around 0.295*pi\")\n",
    "print(angle_between_two_quantum_states([3/5,4/5],[1,0]),\"is the angle between |0> and the quantum state [3/5,4/5]\")\n",
    "print(0.295*pi,\"is the value of 0.295*pi\")\n",
    "print()\n",
    "\n",
    "print(\"the angle between |0> and quantum state [-1/(2**0.5),-1/(2**0.5)] is 3pi/4 (135 degree)\")\n",
    "print(angle_between_two_quantum_states([-1/(2**0.5),-1/(2**0.5)],[1,0]),\"is the angle between |0> and quantum state [-1/(2**0.5),-1/(2**0.5)]\")\n",
    "print(3*pi/4,\"is the value of 3*pi/4\",)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    "# OPTIONAL\n",
    "# \n",
    "# you may also test the function angle_between_two_quantum_states\n",
    "#\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Visualization of reflection </h3>\n",
    "\n",
    "We randomly pick two quantum states $ \\ket{u} $ and $ \\ket{v} $.\n",
    "\n",
    "We find the quantum state $ \\ket{u_v} $, which is the reflection of $ \\ket{u} $ over the axis $ \\ket{v} $.\n",
    "\n",
    "We visualize the quantum states $ \\ket{u} $, $ \\ket{v} $, and $ \\ket{u_v} $.\n",
    "\n",
    "We write a function called \"reflection_game\" for this purpose.\n",
    "\n",
    "This function calls four other functions as subroutines:\n",
    "<ol>\n",
    "    <li> Function \"random_quantum_state\" that returns a randomly created a quantum state.</li>\n",
    "    <li> Function \"find_angle_of_a_quantum_state\" that returns an angle uniquely representing a given quantum state.</li>\n",
    "    <li> Function \"visualize_quantum_states\" that visualizes all given quantum states on the unit circle with their labels.</li>\n",
    "    <li> Function \"amplitudes_of_a_quantum_state\" that takes a quantum circuit having a (real-valued) qubit as the input, and then returns the amplitudes of the current quantum state.</li>\n",
    "</ol>\n",
    "\n",
    "We define each subroutine, and then the main function."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Define function <font color=\"blue\">random_quantum_state</b></h4>\n",
    "\n",
    "This function returns a randomly created quantum state on the unit circle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from random import randrange\n",
    "# randomly create a quantum state of a qubit\n",
    "def random_quantum_state():\n",
    "    first_entry = randrange(100)\n",
    "    first_entry = first_entry/100\n",
    "    first_entry = first_entry**0.5\n",
    "    if randrange(2) == 0: # determine the sign of the first entry\n",
    "        first_entry = -1 * first_entry\n",
    "    second_entry = 1 - (first_entry**2)\n",
    "    second_entry = second_entry**0.5 # the second entry cannot be nonnegative\n",
    "    if randrange(2) == 0: # determine the sign\n",
    "       second_entry = -1 * second_entry\n",
    "    return [first_entry,second_entry]\n",
    "\n",
    "print(\"function 'random_quantum_state' is defined now, and so it can be used in the following part\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Define function <font color=\"blue\">find_angle_of_a_quantum_state</b></h4>\n",
    "\n",
    "This function returns the angle of a rotation that rotates the state $ \\ket{0} $ to the given quantum state.\n",
    "\n",
    "Such angle can be between 0 and $ 2\\pi $. Therefore, it uniquely defines a quantum state.\n",
    "\n",
    "The difference between this function and function \"angle_between_two_quantum_states\" can be observed from the figure below:\n",
    "<ul>\n",
    "    <li> Function \"angle_between_two_quantum_states\" returns $ \\frac{3 \\pi}{4} $ as the angle between the vectors $ u $ and $ v $. </li>\n",
    "    <li> But function \"find_angle_of_a_quantum_state\" returns $ \\frac{5 \\pi}{4} $ as the angle of the rotation from vector $ u $ to $ v $. </li>  \n",
    "</ul>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"../images/angle_with_zero_state.jpg\" width=\"50%\"> \n",
    "\n",
    "If the second entry of the quantum state is positive, then both functions return the same angle.\n",
    "\n",
    "If the second entry of the quantum state is negative, then the functions return different values.\n",
    "\n",
    "However, we remark that the summation of both values are always $ 2 \\pi $ in the second case."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from math import pi \n",
    "\n",
    "def find_angle_of_a_quantum_state(quantum_state):\n",
    "    # find the angle between quantum_state and [1,0]\n",
    "    angle = angle_between_two_quantum_states(quantum_state,[1,0])\n",
    "    if quantum_state[1] < 0: # the angle is greater than pi\n",
    "        angle = 2 * pi - angle\n",
    "    return angle\n",
    "\n",
    "print(\"function 'find_angle_of_a_quantum_state' is defined now, and so it can be used in the following part\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Test function <font color=\"blue\">find_angle_of_a_quantum_state</b></h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# find the angles of |0>, |1>, -|0>, and -|1>\n",
    "print(find_angle_of_a_quantum_state([1,0]),\"is the angle of |0>, which should be 0*pi=\",0*pi)\n",
    "print(find_angle_of_a_quantum_state([0,1]),\"is the angle of |1>, which should be pi/2=\",pi/2)\n",
    "print(find_angle_of_a_quantum_state([-1,0]),\"is the angle of -|0>, which should be pi=\",pi)\n",
    "print(find_angle_of_a_quantum_state([0,-1]),\"is the angle of -|1>, which should be 3*pi/2=\",3*pi/2)\n",
    "print()\n",
    "\n",
    "# find the angle of H|0> = [1/2**0.5,1/2**0.5]\n",
    "print(find_angle_of_a_quantum_state([1/2**0.5,1/2**0.5]),\"is the angle of H|0>, which should be pi/4=\",pi/4)\n",
    "# find the angle of [-1/2**0.5,1/2**0.5], which is pi/2 more than the previous angle\n",
    "print(find_angle_of_a_quantum_state([-1/2**0.5,1/2**0.5]),\"is pi/2 more than the previous angle, which should be 3*pi/4=\",3*pi/4)\n",
    "# find the angle of [-1/2**0.5,-1/2**0.5], which is pi/2 more than the previous angle\n",
    "print(find_angle_of_a_quantum_state([-1/2**0.5,-1/2**0.5]),\"is pi/2 more than the previous angle, which should be 5*pi/4=\",5*pi/4)\n",
    "# find the angle of [-1/2**0.5,1/2**0.5], which is pi/2 more than the previous angle\n",
    "print(find_angle_of_a_quantum_state([1/2**0.5,-1/2**0.5]),\"is pi/2 more than the previous angle, which should be 7*pi/4=\",7*pi/4)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Function <font color=\"blue\">visualize_quantum_states</font></h4>\n",
    "\n",
    "This function visualize the given quantum states on the unit circle.\n",
    "\n",
    "The input should be a list of quantum states with their labels, i.e., $ [ \\mbox{'label'}, \\mbox{the-first-amplitude}, \\mbox{the-second-amplitude} ] $."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def visualize_quantum_states(quantum_states):\n",
    "    # import the useful tool for drawing figures in pythpn\n",
    "    from matplotlib.pyplot import plot, show, figure, Circle, axis, gca, annotate, arrow, text\n",
    "    # import the constant pi\n",
    "    from math import pi\n",
    "    \n",
    "    figure(figsize=(6,6), dpi=80) # size of the figure\n",
    "    gca().add_patch( Circle((0,0),1,color='black',fill=False) ) # draw the circle\n",
    "    # auxiliary points\n",
    "    plot(-1.3,0)\n",
    "    plot(1.3,0)\n",
    "    plot(0,1.3)\n",
    "    plot(0,-1.3)\n",
    "    # axes\n",
    "    arrow(0,0,1.1,0,head_width=0.04, head_length=0.08)\n",
    "    arrow(0,0,-1.1,0,head_width=0.04, head_length=0.08)\n",
    "    arrow(0,0,0,-1.1,head_width=0.04, head_length=0.08)\n",
    "    arrow(0,0,0,1.1,head_width=0.04, head_length=0.08)\n",
    "    \n",
    "    # draw all quantum states\n",
    "\n",
    "    for quantum_state in quantum_states:\n",
    "        # show the quantum state as an arrow on the diagram\n",
    "        state_name = quantum_state[0] # label of the quantum state \n",
    "        x_value = quantum_state[1] # amplitude of |0>\n",
    "        y_value = quantum_state[2] # amplitude of |1>\n",
    "        # draw the arrow\n",
    "        arrow(0,0,x_value,y_value,head_width=0.04, head_length=0.04,color='blue')\n",
    "\n",
    "         # the following code is used to write the name of quantum states\n",
    "        if x_value<0: text_x_value=x_value-0.1\n",
    "        else: text_x_value=x_value+0.05\n",
    "        if y_value<0: text_y_value=y_value-0.1\n",
    "        else: text_y_value=y_value+0.05       \n",
    "        text(text_x_value,text_y_value,state_name)\n",
    "\n",
    "    show() # show the diagram\n",
    "# end of function\n",
    "\n",
    "print(\"function 'visualize_quantum_states' is defined now, and so it can be used in the following part\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Test function <font color=\"blue\">visualize_quantum_states</b></h4>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# define a list of three quantum states with their labels\n",
    "all_quantum_states =[\n",
    "    ['u',-1/2**0.5,-1/2**0.5],\n",
    "    ['v',3/5,4/5],\n",
    "    ['|1>',0,1]\n",
    "]\n",
    "\n",
    "# visualize all quantum states\n",
    "visualize_quantum_states(all_quantum_states)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h4> Function <font color=\"blue\">amplitudes_of_a_quantum_state</font></h4>\n",
    "\n",
    "This function takes a quantum circuit having a (real-valued) qubit as the input, and then returns the amplitudes of the current quantum state."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def amplitudes_of_a_quantum_state(quantum_circuit):\n",
    "    # import all necessary objects and methods for quantum circuits\n",
    "    from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer\n",
    "    \n",
    "     # the following code is used to get the quantum state of a quantum circuit\n",
    "    job = execute(quantum_circuit,Aer.get_backend('statevector_simulator'))\n",
    "    current_quantum_state=job.result().get_statevector(quantum_circuit) \n",
    "    \n",
    "    # now we read the real parts of the amplitudes\n",
    "    the_first_amplitude = current_quantum_state[0].real # amplitude of |0>\n",
    "    the_second_amplitude = current_quantum_state[1].real # amplitude of |1>\n",
    "    \n",
    "    return[the_first_amplitude,the_second_amplitude]\n",
    "# end of function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Function <font color=\"blue\">reflection_game</font></h3>\n",
    "\n",
    "This is the function to visualize the reflection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def reflection_game():\n",
    "    # randomly construct u\n",
    "    u = random_quantum_state()\n",
    "    print(\"u is\",u)\n",
    "\n",
    "    # randomly construct v\n",
    "    v = random_quantum_state()\n",
    "    print(\"v is\",v)\n",
    "\n",
    "    print()    \n",
    "    # the angle representing u uniquely\n",
    "    angle_of_u = find_angle_of_a_quantum_state(u)\n",
    "    print(\"the angle uniquely representing u is\",angle_of_u,\"=\",angle_of_u/pi*180,\"degrees\")\n",
    "\n",
    "    # the angle representing v uniquely\n",
    "    angle_of_v = find_angle_of_a_quantum_state(v)\n",
    "    print(\"the angle uniquely representing v is\",angle_of_v,\"=\",angle_of_v/pi*180,\"degrees\")\n",
    "\n",
    "    # the angle between u and v\n",
    "    angle_between_u_and_v = angle_of_u-angle_of_v\n",
    "    print(\"the angle between u and v is\",angle_between_u_and_v,\"=\",angle_between_u_and_v/pi*180,\"degrees\")\n",
    "\n",
    "    #\n",
    "    #\n",
    "    # we find |u>, |v>, and |uv> by writing a quantum program\n",
    "    #\n",
    "    #\n",
    "    \n",
    "    # start in |0>\n",
    "    # rotate with u_angle to find |u>\n",
    "    # rotate with -angle_between_u_and_v to find |v>\n",
    "    # rotate with -angle_between_u_and_v once more to find the reflection of |u> over the axis |v>\n",
    "    # we use ry-gatefor the rotations\n",
    "\n",
    "    # COPY-PASTE from the previous programs\n",
    "\n",
    "    # import all necessary objects and methods for quantum circuits\n",
    "    from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer\n",
    "    from qiskit.tools.visualization import matplotlib_circuit_drawer as drawer\n",
    "    \n",
    "\n",
    "    # we define a quantum circuit with one qubit and one bit\n",
    "    qreg1 =  QuantumRegister(1) # quantum register with a single qubit\n",
    "    creg1 = ClassicalRegister(1) # classical register with a single bit\n",
    "    mycircuit1 = QuantumCircuit(qreg1,creg1) # quantum circuits with quantum and classical registers\n",
    "\n",
    "    # store all quantum states with their labels\n",
    "    all_quantum_states = [\n",
    "        ['0',1,0] # start with |0>\n",
    "    ]\n",
    "\n",
    "    print()# print an empty line\n",
    "    \n",
    "    # 1)\n",
    "    # already started in |0>\n",
    "    # rotate with angle_of_u to find |u>\n",
    "    mycircuit1.ry(2*angle_of_u,qreg1[0]) \n",
    "    \n",
    "    # get the amplitudes of the current quantum state\n",
    "    [x_value,y_value] = amplitudes_of_a_quantum_state(mycircuit1)\n",
    "\n",
    "    all_quantum_states.append(['u',x_value,y_value]) # add the quantum state u\n",
    "\n",
    "    # 2)\n",
    "    # rotate with -angle_between_u_and_v to find |v>\n",
    "    mycircuit1.ry(-2*angle_between_u_and_v,qreg1[0]) \n",
    "\n",
    "   # get the amplitudes of the current quantum state\n",
    "    [x_value,y_value] = amplitudes_of_a_quantum_state(mycircuit1)\n",
    "\n",
    "    all_quantum_states.append(['v',x_value,y_value]) # add the quantum state v\n",
    "\n",
    "\n",
    "    # 3)\n",
    "    # rotate with -angle_between_u_and_v once more to find the reflection of |u> over the axis |v>\n",
    "    mycircuit1.ry(-2*angle_between_u_and_v,qreg1[0]) \n",
    "\n",
    "    # get the amplitudes of the current quantum state\n",
    "    [x_value,y_value] = amplitudes_of_a_quantum_state(mycircuit1)\n",
    "\n",
    "    all_quantum_states.append(['uv',x_value,y_value]) # add the quantum state uv\n",
    "\n",
    "    print(\"all quantum states:\")\n",
    "    print(all_quantum_states)\n",
    "\n",
    "    # visualize all quantum states\n",
    "    visualize_quantum_states(all_quantum_states)\n",
    "# end of function\n",
    "\n",
    "print(\"function 'reflection game' is defined now, and so it can be used in the following part\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h3> Play with <font color=\"blue\">reflection_game</font> </h3>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# game 1\n",
    "reflection_game()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# game 2\n",
    "reflection_game()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# game 3\n",
    "reflection_game()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# game 4\n",
    "reflection_game()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# game 5\n",
    "reflection_game()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# games 6 - 20\n",
    "for i in range(6,21):\n",
    "    reflection_game()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
